home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
tex
/
dvi
/
dvipssrc.zoo
/
dospecia.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-15
|
20KB
|
720 lines
/*
* This routine handles special commands;
* predospecial() is for the prescan, dospecial() for the real thing.
*/
#include "structures.h" /* The copyright notice in that file is included too! */
#include <ctype.h>
extern int atoi();
/*
* These are the external routines called:
*/
/**/
#ifdef TPIC
/*
* Fri Mar 9 1990 jourdan@minos.inria.fr (MJ)
* Upgraded to accommodate tpic release 2.0 extended output language.
* Should prove upward compatible!
*/
extern void setPenSize();
extern void flushPath();
extern void flushDashed();
extern void flushDashed();
extern void addPath();
extern void arc();
extern void flushSpline();
extern void shadeLast();
extern void whitenLast();
extern void blackenLast();
extern void SetShade() ;
#endif
extern shalfword dvibyte() ;
extern int add_header() ;
extern void hvpos() ;
extern void figcopyfile() ;
extern char *malloc() ;
extern void nlcmdout() ;
extern void cmdout() ;
extern void numout() ;
extern void scout() ;
extern void stringend() ;
extern void error() ;
extern void psflush() ;
extern char errbuf[] ;
extern shalfword linepos;
extern Boolean usesspecial ;
extern int landscape ;
extern char *paperfmt ;
extern char *nextstring;
extern char *maxstring;
extern char *oname;
extern FILE *bitfile;
extern int quiet;
extern fontdesctype *curfnt ;
extern int actualdpi ;
extern int vactualdpi ;
extern integer hh, vv;
extern int lastfont ;
extern real conv ;
extern real vconv ;
#ifdef DEBUG
extern integer debug_flag;
#endif
extern void scanfontcomments() ;
struct bangspecial {
struct bangspecial *next ;
char actualstuff[1] ; /* more space will actually be allocated */
} *bangspecials = NULL ;
#ifdef EMTEX
/* subset of emtex specials */
#define EMMAX 1613 /* maximum number of emtex special points */
#define TRUE 1
#define FALSE 0
struct empt {
shalfword point;
integer x, y;
};
struct empt *empoints = NULL;
boolean emused = FALSE; /* true if em points used on this page */
integer emx, emy;
struct emunit {
char *unit;
float factor;
};
struct emunit emtable[] = {
{"pt",72.27},
{"pc",72.27/12},
{"in",1.0},
{"bp",72.0},
{"cm",2.54},
{"mm",25.4},
{"dd",72.27/(1238/1157)},
{"cc",72.27/12/(1238/1157)},
{"sp",72.27*65536},
{"",0.0}
};
/* clear the empoints array if necessary */
void
emclear()
{
int i;
if (emused && empoints)
for (i=0; i<EMMAX; i++)
empoints[i].point = 0;
emused = FALSE ;
}
/* put an empoint into the empoints array */
struct empt *emptput(point, x, y)
shalfword point;
integer x, y;
{
int i, start;
emused = TRUE;
start = point % EMMAX;
i = start;
while ( empoints[i].point != 0 ) {
if ( empoints[i].point == point )
break;
i++;
if (i >= EMMAX)
i = 0;
if (i == start) {
sprintf(errbuf,"!Too many em: special points");
error(errbuf);
}
}
empoints[i].point = point;
empoints[i].x = x;
empoints[i].y = y;
return(&empoints[i]);
}
/* get an empoint from the empoints array */
struct empt *emptget(point)
shalfword point;
{
int i, start;
start = point % EMMAX;
i = start;
if (emused == TRUE)
while ( empoints[i].point != 0 ) {
if (empoints[i].point == point)
return(&empoints[i]);
i++;
if (i >= EMMAX)
i = 0;
if (i == start)
break;
}
sprintf(errbuf,"!em: point %d not defined",point);
error(errbuf);
return(NULL); /* never returns due to error */
}
/* convert width into dpi units */
float emunits(width,unit)
float width;
char *unit;
{
struct emunit *p;
for (p=emtable; *(p->unit)!='\0'; p++) {
if (strcmp(p->unit,unit)==0)
return( width * actualdpi / p->factor );
}
return (-1.0); /* invalid unit */
}
#endif /* EMTEX */
static void trytobreakout(p)
register char *p ;
{
register int i ;
register int instring = 0 ;
int lastc = 0 ;
i = 0 ;
while (*p) {
if (i > 65 && *p == ' ' && instring == 0) {
(void)putc('\n', bitfile) ;
i = 0 ;
} else {
(void)putc(*p, bitfile) ;
i++ ;
}
if (*p == '(' && lastc != '\\')
instring = 1 ;
else if (*p == ')' && lastc != '\\')
instring = 0 ;
lastc = *p ;
p++ ;
}
}
static void dobs(q)
register struct bangspecial *q ;
{
if (q) {
dobs(q->next) ;
trytobreakout(q->actualstuff) ;
}
}
void
outbangspecials() {
if (bangspecials) {
cmdout("TeXDict") ;
cmdout("begin") ;
cmdout("@defspecial\n") ;
dobs(bangspecials) ;
cmdout("\n@fedspecial") ;
cmdout("end") ;
}
}
/* We recommend that new specials be handled by the following general
* (and extensible) scheme, in which the user specifies one or more
* `key=value' pairs separated by spaces.
* The known keys are given in KeyTab; they take values
* of one of the following types:
*
* None: no value, just a keyword (in which case the = sign is omitted)
* String: the value should be "<string without double-quotes"
* or '<string without single-quotes'
* Integer: the value should be a decimal integer (%d format)
* Number: the value should be a decimal integer or real (%f format)
* Dimension: like Number, but will be multiplied by the scaledsize
* of the current font and converted to default PostScript units
* (Actually, strings are allowed in all cases; the delimiting quotes
* are simply stripped off if present.)
*
*/
typedef enum {None, String, Integer, Number, Dimension} ValTyp;
typedef struct {
char *Entry;
ValTyp Type;
} KeyDesc;
#define NKEYS (sizeof(KeyTab)/sizeof(KeyTab[0]))
KeyDesc KeyTab[] = {{"psfile", String}, /* j==0 in the routine below */
{"ifffile", String}, /* j==1 */
{"tekfile", String}, /* j==2 */
{"hsize", Number},
{"vsize", Number},
{"hoffset", Number},
{"voffset", Number},
{"hscale", Number},
{"vscale", Number},
{"angle", Number},
{"llx", Number},
{"lly", Number},
{"urx", Number},
{"ury", Number},
{"rwi", Number}};
#ifdef VMS
#define Tolower _tolower
#else
/*
* compare strings, ignore case
*/
char Tolower(c)
register char c ;
{
if ('A' <= c && c <= 'Z')
return(c+32) ;
else
return(c) ;
}
#endif
int IsSame(a, b)
char *a, *b;
{
for( ; *a != '\0'; )
if( Tolower(*a++) != Tolower(*b++) )
return( 0 );
return( *b == '\0' );
}
char *KeyStr, *ValStr ; /* Key and String values found */
long ValInt ; /* Integer value found */
float ValNum ; /* Number or Dimension value found */
char *GetKeyVal(str,tno) /* returns NULL if none found, else next scan point */
char *str ; /* starting point for scan */
int *tno ; /* table entry number of keyword, or -1 if keyword not found */
{
register char *s ;
register int i ;
register char t ;
for (s=str; *s <= ' ' && *s; s++) ; /* skip over blanks */
if (*s == '\0')
return (NULL) ;
KeyStr = s ;
while (*s>' ' && *s!='=') s++ ;
if (t = *s)
*s++ = 0 ;
for(i=0; i<NKEYS; i++)
if( IsSame(KeyStr, KeyTab[i].Entry) )
goto found ;
*tno = -1;
return (s) ;
found: *tno = i ;
if (KeyTab[i].Type == None)
return (s) ;
if (t && t <= ' ') {
for (; *s <= ' ' && *s; s++) ; /* now look for the value part */
if ((t = *s)=='=')
s++ ;
}
ValStr = "" ;
if ( t == '=' ) {
while (*s <= ' ' && *s)
s++ ;
if (*s=='\'' || *s=='\"')
t = *s++ ; /* get string delimiter */
else t = ' ' ;
ValStr = s ;
while (*s!=t && *s)
s++ ;
if (*s)
*s++ = 0 ;
}
switch (KeyTab[i].Type) {
case Integer:
if(sscanf(ValStr,"%ld",&ValInt)!=1) {
sprintf(errbuf,"Non-integer value (%s) given for keyword %s",
ValStr, KeyStr) ;
error(errbuf) ;
ValInt = 0 ;
}
break ;
case Number:
cas